﻿
using SharpDepend.Datatypes;
using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer;
using ZquenceStudio3Host.Graphics.Components;
using ZquenceStudio3Host.Graphics.GUI;

namespace DefaultDspPlugins.UI.Common.Modulizer.Engine.GUIv2.Editors
{
    class BackEndPanel : Panel
    {
        private BackendToolbar mToolbar;
        private ToolboxPanel mToolbox;

        public ToolboxPanel Toolbox { get { return mToolbox; } }

        public BackendToolbar Toolbar { get { return mToolbar; } }

        public BackEndPanel(BasicGuiManager manager, ModulizerTrackArea trackArea, ModulizerUIv2 modulizerUI, bool mobile)
            : base(manager)
        {
            BackgroundColor = Color.Transparent;

            mToolbar = new BackendToolbar(manager, trackArea, modulizerUI);
            mToolbar.BackgroundColor = Color.Gray;
            AddPart(mToolbar);

            mToolbox = new ToolboxPanel(manager, modulizerUI);
            mToolbox.BackgroundColor = Color.Gray;
            AddPart(mToolbox);

            if (mobile)
            {
                mToolbar.DimensionInProcent = true;
                mToolbar.Width = 100;
                mToolbar.Height = 6;

                mToolbox.DimensionInProcent = true;
                mToolbox.Y = 6;
                mToolbox.Width = 15;
                mToolbox.Height = 94;
            }
            else
            {
                Events.OnScaleChanged += Events_OnScaleChanged;
            }
        }

        private void Events_OnScaleChanged()
        {
            mToolbar.Width = this.RealWidth;
            mToolbar.Height = 32;

            mToolbox.Y = mToolbar.Height;
            mToolbox.Width = 200;
            mToolbox.Height = this.RealHeight - mToolbar.Height;
        }

        internal bool IsInArea(double x, double y)
        {
            return !(mToolbar.IsMouseOver(x, y, 0) || mToolbox.IsMouseOver(x, y, 0));
        }
    }
}
